class ListNode(object):
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


class Solution(object):
    def splitListToParts(self, head, k):
        """
        :type head: ListNode
        :type k: int
        :rtype: List[ListNode]
        """
        n = 0
        node = head
        while node:
            n += 1
            node = node.next
        t = n // k
        l = n % k
        out = []
        node = head
        for i in range(k):
            out.append(node)
            if i < l:
                for m in range(t):
                    node = node.next
                if node:
                    next_node = node.next
                    node.next = None
                    node = next_node
            else:
                for m in range(t - 1):
                    node = node.next
                if node:
                    next_node = node.next
                    node.next = None
                    node = next_node
        return out




